<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">

		<title>信义物流管理员管理</title>
	</head>
	<link rel="stylesheet" type="text/css" href="js/bootstarp-3.3.7/css/bootstrap.min.css" />
	<script src="js/jquery-3.2.0.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<link rel="stylesheet" type="text/css" href="js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
	<script src="js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>

	<script type="text/javascript">
		$(function() {

			$("table").bootstrapTable({
				url: "login/loginall.lgg",
				pagination: true,
				pageSize: 5,
				queryParams: queryParams,
				columns: [{
					field: 'user_id',
					title: '管理员编号',
					align: 'center',
				}, {
					field: 'login_id',
					title: '管理员用户名',
					align: 'center',
				}, {
					field: 'name',
					title: '管理员姓名',
					align: 'center',
				}, {
					field: 'email',
					title: '管理员邮箱',
					align: 'center',
				}, {
					field: 'phone',
					title: '管理员手机号',
					align: 'center',
				}, {
					field: 'address',
					title: '管理员地址',
					align: 'center',
				}, {
					field: 'region_name',
					title: '管理员所在城市',
					align: 'center',
				}, {
					field: 'role_name',
					title: '角色',
					align: 'center',
				}, {
					title: '操作',
					align: 'center',
					formatter: function(value, row, index) {
						return '<button onclick="delet(' + row.user_id + ')" class="btn btn-danger glyphicon glyphicon-trash"></button>  <button onclick="upda(' + row.user_id + ')" class="btn btn-info glyphicon glyphicon-edit"></button>'
					}
				}]

			})
		})

		$.getJSON("login/roleall.lgg", function(data) {
			for(var i = 0; i < data.length; i++) {
				$("#role_id,#role_id2,#role_id3").append("<option value='" + data[i].role_id + "'>" + data[i].role_name + "</option>")
			}

		})
		
		$.getJSON("login/regionall.lgg", function(data) {
			for(var i = 0; i < data.length; i++) {
				$("#region_id2,#region_id3").append("<option value='" + data[i].region_id + "'>" + data[i].region_name + "</option>")
			}

		})
		
		function qqq() {			
					var addyouxiang= new RegExp(/^[0-9|A-z|_]{1,17}[@][0-9|A-z]{1,3}.(com)$/)
					var addmima= new RegExp(/^[a-zA-Z][0-9]{5,15}$/)					
					var addsj= new RegExp(/^1[3|4|5|8|7][0-9]\d{8}$/)
					
   					var email2 = document.getElementById("email2").value;
   					var password =document.getElementById("password2").value;
   					var phone =document.getElementById("phone2").value;
			
			if ($("#login_id2").val().trim().length==0||$("#name2").val().trim().length==0||$("#email2").val().trim().length==0||$("#phone2").val().trim().length==0||$("#password2").val().trim().length==0||$("#address2").val().trim().length==0||$("#login_id2").val().trim().length==0) {
					alert("请把新的管理员信息填写完整")		
			}else{
				if (addyouxiang.test(email2)) {
					if (addmima.test(password)) {
						if (addsj.test(phone)) {
								add();
								
						} else{
							alert("手机格式必须是以1开头3,4,5,7,8随机一位为第二位，长度在11位")
						}
					} else{
						alert("密码格式必须是以字母开头，长度在6-15之间")
					}
									
				} else{
					alert("请输入正确的邮箱格式")
				}				
			}	
		}
		
		function qqq2() {			
					var addyouxiang= new RegExp(/^[0-9|A-z|_]{1,17}[@][0-9|A-z]{1,3}.(com)$/)
					var addmima= new RegExp(/^[a-zA-Z][0-9]{5,15}$/)					
					var addsj= new RegExp(/^1[3|4|5|8|7][0-9]\d{8}$/)
					
   					var email2 = document.getElementById("email3").value;
   					var password =document.getElementById("password3").value;
   					var phone =document.getElementById("phone3").value;
   					
			
			if ($("#login_id3").val().trim().length==0||$("#name3").val().trim().length==0||$("#email3").val().trim().length==0||$("#phone3").val().trim().length==0||$("#password3").val().trim().length==0||$("#address3").val().trim().length==0||$("#login_id3").val().trim().length==0) {
					alert("请把修改的管理员信息填写完整")	
			}else{
				if (addyouxiang.test(email2)) {
					if (addmima.test(password)) {
						if (addsj.test(phone)) {
								up();
								
						} else{
							alert("手机格式必须是以1开头3,4,5,7,8随机一位为第二位，长度在11位")
						}
					} else{
						alert("密码格式必须是以字母开头，长度在6-15之间")
					}
									
				} else{
					alert("请输入正确的邮箱格式")
				}				
			}	
		}
		
		function add(){
			$.ajax({
				type: "post",
				url: "login/loginuserjudgment.lgg",
				data:"login_id="+$("#login_id2").val(),
				success: function(data) {
					if (data==0) {
						$.ajax({
							type: "post",
							url: "login/loginadd.lgg",
							data:$("#for").serialize(),
							success: function(data) {
								$("#myModal").modal("hide")
								$("#tab").bootstrapTable('refresh')						
							}
						});	
					} else{
						alert("用户名已存在")
					}									
				}
			});	
			
			
			
			
				
			
		}
		
		
		
		function up() {
			  
				if ($("#login_id3").val().trim().length==0||$("#name3").val().trim().length==0||$("#email3").val().trim().length==0||$("#phone3").val().trim().length==0||$("#password3").val().trim().length==0||$("#address3").val().trim().length==0||$("#login_id3").val().trim().length==0) {
					alert("请把修改的管理员信息填写完整")
			}
				
				else{
$.ajax({
					type: "post",
					url: "login/loginup.lgg",
					data:$("#for2").serialize(),
					success: function(data) {
						$("#myModal2").modal("hide")
						$("#tab").bootstrapTable('refresh')
					}
				});
					
					
					
				
				}
			}
		
		
			function upda(user_id) {
				$("#myModal2").modal("show")
				$.ajax({
					type: "post",
					url: "login/loginse.lgg",
					data: "user_id=" + user_id,
					success: function(data) {
						$("#user_id").val(data.user_id);
						$("#login_id3").val(data.login_id);
						$("#name3").val(data.name);
						$("#email3").val(data.email);
						$("#phone3").val(data.phone);
						$("#password3").val(data.password);
						$("#address3").val(data.address);
						$("#region_id3").val(data.region_id);
						$("#role_id3").val(data.role_id);
						$("#myModal2").modal('show');
					}
				});
			}
		
		
			function btn2() {
				$("#login_id2").val("");
				$("#name2").val("");
				$("#email2").val("");
				$("#phone2").val("");
				$("#password2").val("");
				$("#address2").val("");
				$("#region_id2").val("");
				$("#role_id2").val("");
				$("#myModal").modal("show");
			}
		
		
		

		function delet(user_id) {
			$.ajax({
				type: "post",
				url: "login/logindele.lgg",
				data: "user_id=" + user_id,
				success: function(data) {

					$("#tab").bootstrapTable('refresh')
				}
			});
		}

		function queryParams(Params) {
			return {
				'login_id': $("#login_id").val(),
				'name': $("#name").val(),
				'role_id': $("#role_id").val(),
			}
		}

		function select() {
			$("#tab").bootstrapTable('refresh')
		}
		
		$(document).ready(function () {

   				 $('#password2').validate({debug:true});

}			);


	function yhm()  {
		alert("用户名不可更改")
	}	
	</script>

	<body>

		<div align="center">
			<form class="form-inline">
				<div class="form-group">
					<label for="exampleInputEmail2">查询：</label>
					<input type="text" class="form-control" id="login_id" name="login_id" placeholder="请输入管理员用户名">
					<input type="text" class="form-control" id="name" name="name" placeholder="请输入管理员姓名">

					<select class="form-control" id="role_id" name="role_id">
						<option value="">请选择角色</option>
					</select>
					<button type="button" class="btn btn-default glyphicon glyphicon-search" onclick="select()"></button>
					<button type="button" class="btn btn-primary glyphicon glyphicon-plus"  onclick="btn2()"></button>
				</div>
				</form>
		</div>

		<!-- Button trigger modal -->

		<!-- Modal -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">添加新的管理员</h4>
					</div>
					<div class="modal-body">


					<form class="form-horizontal" id="for">
					 <div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员用户名：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="login_id2" name="login_id" placeholder="请输入管理员用户名">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员姓名：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="name2" name="name" placeholder="请输入管理员用户名">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员密码：</label>
   								 <div class="col-sm-8">
     								 <input type="password" class="form-control" id="password2" name="password"  pattern="[A-Za-z0-9\w]{6,20}" placeholder="请输入管理员用户名">
    							</div>
  					</div>
  					
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员邮箱：</label>
   								 <div class="col-sm-8">
     								 <input type="email" class="form-control" id="email2" name="email" placeholder="请输入管理员邮箱">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员手机号：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="phone2" name="phone" placeholder="请输入管理员手机号">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员地址：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="address2" name="address" placeholder="请输入管理员用户名">
    							</div>
  					</div>
  					
  				
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员所在城市：</label>
   								 <div class="col-sm-8">
									<select class="form-control" id="region_id2" name="region_id">
										<option value="">请选择城市</option>
									</select>    							
   								 </div>
  					</div>
  					
  					
  						
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员角色：</label>
   								 <div class="col-sm-8">
									<select class="form-control" id="role_id2" name="role_id">
										<option value="">请选择角色</option>
									</select>    							
   								 </div>
  					</div>
							

						</form>
						
						
					
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal" onclick="close()"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok"  onclick="qqq()"></button>
					</div>
				</div>
			</div>
		</div>
		
		
		
		
		
				<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h4 class="modal-title" id="myModalLabel">更新的管理员</h4>
					</div>
					<div class="modal-body">


					<form class="form-horizontal" id="for2">
					 <div class="form-group">
					 	<input type="hidden" class="form-control" id="user_id" name="user_id">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员用户名：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" readonly  id="login_id3" name="login_id" placeholder="请输入管理员用户名" onclick="yhm()">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员姓名：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="name3" name="name" placeholder="请输入管理员用户名" >
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员密码：</label>
   								 <div class="col-sm-8">
     								 <input type="password" class="form-control" id="password3" name="password" placeholder="请输入管理员用户名">
    							</div>
  					</div>
  					
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员邮箱：</label>
   								 <div class="col-sm-8">
     								 <input type="email" class="form-control" id="email3" name="email" placeholder="请输入管理员邮箱">
    							</div>
  					</div>
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员手机号：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="phone3" name="phone" placeholder="请输入管理员手机号">
    							</div>
  					</div>
  					
  					
  					  <div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员地址：</label>
   								 <div class="col-sm-8">
     								 <input type="text" class="form-control" id="address3" name="address" placeholder="请输入管理员地址">
    							</div>
  					</div>
  					
  					
  					
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员所在城市：</label>
   								 <div class="col-sm-8">
									<select class="form-control" id="region_id3" name="region_id">
										<option value="">请选择城市</option>
									</select>    							
   								 </div>
  					</div>
  					
  					
  					
  					<div class="form-group">
    						<label for="inputEmail3" class="col-sm-3 control-label">管理员角色：</label>
   								 <div class="col-sm-8">
									<select class="form-control" id="role_id3" name="role_id">
										<option value="">请选择角色</option>
									</select>    							
   								 </div>
  					</div>
							

						</form>
						
						
					
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-danger glyphicon glyphicon-remove" data-dismiss="modal" onclick="close()"></button>
						<button type="button" class="btn btn-success glyphicon glyphicon-ok"  onclick="qqq2()"></button>
					</div>
				</div>
			</div>
		</div>

		<table border="" cellspacing="" cellpadding="" id="tab"  class="table table-striped">
			 
		</table>

	</body>

</html>